package com.ruoyi.cms.chat.controller;

import com.ruoyi.cms.chat.entity.CmsChatHistory;
import com.ruoyi.cms.chat.service.CmsChatHistoryService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.system.service.ISysUserService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


/**
 * 文章管理Controller
 * 
 *     
 *       
 */
@RestController
@RequestMapping("/cms/chat")
public class CmsChatController extends BaseController {

    @Resource
    private ISysUserService sysUserService;

    @GetMapping("/cms/userList")
    public AjaxResult cmsList() {
        List<SysUser> list = sysUserService.list();
        return AjaxResult.success(list);
    }
    @Resource
    private CmsChatHistoryService cmsChatHistoryService;

    /**
     * 分页查询
     *
     * @param cmsChatHistory 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @GetMapping
    public ResponseEntity<Page<CmsChatHistory>> queryByPage(CmsChatHistory cmsChatHistory, PageRequest pageRequest) {
        return ResponseEntity.ok(this.cmsChatHistoryService.queryByPage(cmsChatHistory, pageRequest));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<CmsChatHistory> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.cmsChatHistoryService.queryById(id));
    }
    @GetMapping("/history")
    public AjaxResult queryHistory(@RequestParam String fromUsername, @RequestParam String targetUsername) {
        return AjaxResult.success(this.cmsChatHistoryService.queryHistory(Integer.valueOf(fromUsername),Integer.valueOf(targetUsername)));
    }
    /**
     * 新增数据
     *
     * @param cmsChatHistory 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<CmsChatHistory> add(CmsChatHistory cmsChatHistory) {
        return ResponseEntity.ok(this.cmsChatHistoryService.insert(cmsChatHistory));
    }

    /**
     * 编辑数据
     *
     * @param cmsChatHistory 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<CmsChatHistory> edit(CmsChatHistory cmsChatHistory) {
        return ResponseEntity.ok(this.cmsChatHistoryService.update(cmsChatHistory));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Integer id) {
        return ResponseEntity.ok(this.cmsChatHistoryService.deleteById(id));
    }

    }

